import 'dart:typed_data';

import 'package:json_annotation/json_annotation.dart';
import 'package:frontend/models/briefItems.dart';
import 'package:frontend/models/utils.dart';

part 'itemInfo.g.dart';

@JsonSerializable(explicitToJson: true)
class ItemInfo {
  @JsonKey(toJson: bytes2base64, fromJson: base2bytes)
  Uint8List img;
  String name;
  int price;
  int id;
  String ownerName;
  String description;
  int seller_id;
  List<Comment> comments;

  ItemInfo(this.img, this.name, this.price, this.id, this.ownerName,
      this.description, this.comments, this.seller_id);

  factory ItemInfo.fromJson(Map<String, dynamic> json) =>
      _$ItemInfoFromJson(json);

  Map<String, dynamic> toJson() => _$ItemInfoToJson(this);
}

@JsonSerializable(explicitToJson: true)
class Comment {
  @JsonKey(toJson: bytes2base64, fromJson: base2bytes)
  Uint8List userImg;
  String userName;
  String content;

  factory Comment.fromJson(Map<String, dynamic> json) =>
      _$CommentFromJson(json);

  Comment(this.userName, this.content, this.userImg);

  Map<String, dynamic> toJson() => _$CommentToJson(this);
}
